#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2*1e5+2;

const int base1 = 31;
const int base2 = 53;
const int mod1 = 1e9+7;
const int mod2 = 985211211;


string s1,s2,stemp;
unordered_set<LL> se1;
unordered_set<LL> se2;
vector<int> edges[N];
LL num1,num2;
bool visit[N];

inline LL qpow(int base,int n,int mod){
    LL res = 1;
    LL b = base;
    while(n){
        if(n&1){
            res = res*b%mod;
        }
        b = b*b%mod;
        n >>= 1;
    }
    return res;
}

int main(){
    while(cin>>s1){
        if(s1==".") break;
        num1 = num2 = 0;
        for(int i=0;s1[i]!='\0';i++){
            num1 = (num1*base1+(s1[i]-'A'+1))%mod1;
            num2 = (num2*base2+(s1[i]-'A'+1))%mod2;
        }
        se1.insert(num1);
        se2.insert(num2);
    }

    s2 = "";
    while(cin>>stemp) s2 += stemp;

    int num;
    for(int i=1; i<=10&&i<=s2.length(); i++){
        num1 = num2 = 0;
        int j;
        for(j=0;j<i&&s2[j]!='\0';j++){
            num = s2[j]-'A'+1;
            num1 = (num1*base1+num)%mod1;
            num2 = (num2*base2+num)%mod2;
        }
        if(se1.count(num1)&& se2.count(num2))  edges[0].emplace_back(i);
        while(s2[j]!='\0'){
            num = s2[j-i]-'A'+1;
            num1 = ( (num1-num*qpow(base1,i-1,mod1)%mod1+mod1)%mod1*base1%mod1+ s2[j]-'A'+1)%mod1;
            num2 = ( (num2-num*qpow(base2,i-1,mod2)%mod2+mod2)%mod2*base2%mod2+ s2[j]-'A'+1)%mod2;
            if(se1.count(num1)&& se2.count(num2)){
                edges[j+1-i].emplace_back(j+1);
            }
            ++j;
        }
    }

    
    memset(visit,0,sizeof(visit));
    visit[0] = true;
    queue<int> que;
    que.push(0);
    int ans = 0;
    int c;
    while(!que.empty()){
        c = que.front();
        que.pop();
        for(auto u:edges[c]){
            if(visit[u]) continue;
            visit[u] = true;
            ans = max(ans,u);
            que.push(u);
        }
    }
    printf("%d\n",ans);
    return 0;
}